import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
// import local_remove from '@dfeidao/atom-web/local/remove';
import local_set from '@dfeidao/atom-web/local/set';
import storage_get from '@dfeidao/atom-web/storage/get';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';

import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import P05 from './P05';

import a002 from './a002';
// 搜索查询
export default async function a004(fd: IFeidaoAiBrowserComponent) {
	const client_point_id = fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="client_point_id"]').value;
	const prid = storage_get('productid');
	local_set(fd, "client_point_id", client_point_id);
	const res1 = await nodejs<{ dataArray: Array<{ group_number: string }> }>('function-definition/zj-000001/s003', { filter: { productid: prid, client_type: client_point_id } });
	render(fd, res1, P05, 'P05', 'inner');

	// debugger;
	if (res1.dataArray.length > 0) {
		const group_number = res1.dataArray[0].group_number;
		const div_nodes = fd.data.node.querySelectorAll<HTMLDivElement>('[data-name="div"]');
		div_nodes.forEach((v) => {
			const group_numbers = v.getAttribute('group_number');
			if (group_number === group_numbers) {
				set_node_cls(v, 'bg-c', true);
			} else {
				set_node_cls(v, 'bg-c', false);
			}
		});
		local_set(fd, "group_number", group_number);
	} else {
		const div_node = fd.data.node.querySelector<HTMLDivElement>('[data-name="未分组"]');
		set_node_cls(div_node, 'bg-c', true);
		local_set(fd, "group_number", '');
	}

	await a002(fd);

}
